import request from '@/utils/request'

export function getAllRoles() {
  return request({
    url: '/sys/role/findList',
    method: 'post',
    data: {}
  })
}

export function findRoles(params) {
  return request({
    url: '/sys/role/findList',
    method: 'post',
    data: params
  })
}

export function get(id) {
  return request({
    url: `/sys/role/${id}`,
    method: 'get'
  })
}

export function addRole(value) {
  return request({
    url: '/sys/role/add',
    method: 'post',
    data: value
  })
}

export function updateRole(value) {
  return request({
    url: `/sys/role/update`,
    method: 'post',
    data: value
  })
}

export function deleteRole(id) {
  return request({
    url: `/sys/role/delete`,
    method: 'get',
    params: { 'id': id }
  })
}

export function getPermissions(id) {
  return request({
    url: `/sys/role/getPermissions`,
    method: 'get',
    params: { 'id': id }
  })
}

export function updatePermission(id, keys) {
  return request({
    url: `/sys/role/updatePermission/${id}`,
    method: 'post',
    data: keys
  })
}

export function getPermissionTree() {
  return request({
    url: `/sys/role/getPermissionTree`,
    method: 'get'
  })
}
